package com.syt.service.controller;

import com.alibaba.fastjson.JSONObject;
import com.syt.service.pojo.PhoneBase;
import com.syt.service.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URI;

/**
 * @author ：syt
 * @date ：Created in 2019-10-02 10:32
 * @description：一个phone的所有信息
 */
@RestController
public class PhoneAllController {

    // 基础数据服务
    @Autowired PhoneBaseService baseService;

    // 外观参数服务
    @Autowired PhoneFacadeService facadeService;

    // 配置信息服务
    @Autowired PhoneConfigService configService;

    // 显示信息服务
    @Autowired PhoneShowService showService;

    // 性能数据服务
    @Autowired PhonePowerService powerService;

    // 电池续航参数服务
    @Autowired PhoneBatteryService batteryService;

    // 相机参数服务
    @Autowired PhoneCameraService cameraService;

    /**
     * 定义一个json，用来保存输出结果
     */
    JSONObject json = new JSONObject();

    /**
     * 根据id获取一个phone的所有数据
     * @param id
     * @return
     */
    @GetMapping("/PhoneAllById/{id}")
    public JSONObject getById(@PathVariable Integer id) {
        json.clear();
        json.put("base", baseService.getPhoneByid(id));
        json.put("facade", facadeService.getById(id));
        json.put("config", configService.getById(id));
        json.put("show", showService.getById(id));
//        json.put("power", powerService.getById(id));
        json.put("battery", batteryService.getById(id));
        json.put("camera", cameraService.getById(id));
        return json;
    }

    @GetMapping("/syttest")
    public JSONObject getTest(HttpServletRequest request) {
        RestTemplate client = new RestTemplate();
        String path = "https://3g.163.com/touch/reconstruct/article/list/BBM54PGAwangning/0-10.html";
        JSONObject  jsonObject = client.getForObject(path, JSONObject.class);
        return jsonObject;
    }

}
